package com.qiantu.phone.ui.fragment;

import android.content.Intent;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.hjq.base.BaseAdapter;
import com.qiantu.phone.R;
import com.qiantu.phone.action.StatusAction;
import com.qiantu.phone.app.AppActivity;
import com.qiantu.phone.app.AppFragment;
import com.qiantu.phone.bean.RecommendSceneBean;
import com.qiantu.phone.ui.activity.RecommendSceneDeviceActionActivity;
import com.qiantu.phone.ui.adapter.RecommendSceneAdapter;
import com.qiantu.phone.utils.RecommendSceneParseUtil;
import com.qiantu.phone.widget.StatusLayout;

import java.util.List;

/**
 *
 */
public class RecommendSceneFragment extends AppFragment<AppActivity> implements StatusAction {

    private StatusLayout mStatusLayout;
    private RecyclerView mRecyclerView;
    private RecommendSceneAdapter mRecommendSceneAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_recommend_scene;
    }

    @Override
    protected void initView() {
        mStatusLayout = findViewById(R.id.status_layout);
        mStatusLayout.setBackgroundResource(R.drawable.top_round_16dp_secondary_color3);
        mRecyclerView = findViewById(R.id.recycler_view);
        initRecyclerView();
    }

    private void initRecyclerView() {
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        mRecommendSceneAdapter = new RecommendSceneAdapter(getContext());
        mRecyclerView.setAdapter(mRecommendSceneAdapter);
        mRecommendSceneAdapter.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(RecyclerView recyclerView, View itemView, int position) {
                Intent intent = new Intent(getContext(), RecommendSceneDeviceActionActivity.class);
                intent.putExtra("data", mRecommendSceneAdapter.getData().get(position));
                startActivity(intent);
            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    protected void initData() {
        List<RecommendSceneBean> recommendSceneBeanList = RecommendSceneParseUtil.parseData(getContext());
        mRecommendSceneAdapter.setData(recommendSceneBeanList);
    }

    @Override
    public StatusLayout getStatusLayout() {
        return mStatusLayout;
    }
}